package com.vue.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vue.mapper.BookMapper;
import com.vue.pojo.Book;
import com.vue.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

@Service
@Transactional
public class ImBookService extends ServiceImpl<BookMapper,Book> implements BookService {
    @Autowired
    private BookMapper bookMapper;
    @Override
    public Page<Book> findll(Integer pagenumber, Integer pagesize,String name,String number) {
        QueryWrapper<Book> queryWrapper=new QueryWrapper<>();
        if(!StringUtils.isEmpty(name)){
            queryWrapper.like("name",name);
        }
        if(!StringUtils.isEmpty(number)){
            queryWrapper.eq("payNumber",Integer.parseInt(number));
        }
        Page<Book> order_demoPage=new Page<>(pagenumber,pagesize);
        Page<Book> order_demoPage1 = bookMapper.selectPage(order_demoPage,queryWrapper);
        return order_demoPage1;
    }

    @Override
    public int addOne(Book book) {
        return bookMapper.insert(book);
    }

    @Override
    public int delOne(Integer id) {
        return bookMapper.deleteById(id);
    }

    @Override
    public int up(Book book) {
        return bookMapper.updateById(book);
    }
}
